package com.example.websocketdemo.controller.CIMVUE;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

@RestController
@RequestMapping("/VUESafetyRightProductionRisk")
public class SafetyRightProductionRiskController {
    @GetMapping("/RiskPoints")
    public JSONArray a(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("title","隐患排查总数");
//        jsonObject.put("value","35");
//        jsonObject.put("隐患排查总数", "35");
//        jsonObject.put("重大隐患数量", "0");
//        jsonObject.put("一般隐患数量", "35");
        for (int i = 0; i < 3; i++) {
            if (i == 0) {
                jsonObject.put("title", "隐患排查总数");
                jsonObject.put("value", "15");
            } else if (i == 1) {
                jsonObject.put("title", "重大隐患数量");
                jsonObject.put("value", "5");
            } else {
                jsonObject.put("title", "一般隐患数量");
                jsonObject.put("value", "10");
            }
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    @GetMapping("/great")
    public JSONArray great(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("已整改", "0");
//        jsonObject.put("未整改", "0");
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                jsonObject.put("title", "已整改");
                jsonObject.put("value", "0");
            } else {
                jsonObject.put("title", "未整改");
                jsonObject.put("value", "0");
            }
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    @GetMapping("/video")
    public JSONArray video(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject3 = new JSONObject();
        JSONObject jsonObject4 = new JSONObject();
        jsonObject.put("title","视频");
        jsonObject1.put("title","视频");
        jsonObject3.put("title","视频");
        jsonObject.put("src","https://www.w3schools.com/html/movie.mp4");
        jsonObject1.put("src","https://www.w3schools.com/html/movie.mp4");
        jsonObject3.put("src","https://www.w3schools.com/html/movie.mp4");

        jsonArray.add(jsonObject);
        jsonArray.add(jsonObject1);
        jsonArray.add(jsonObject3);
        return jsonArray;
    }

    @GetMapping("/ordinary")
    public JSONArray ordinary(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("已整改", "0");
//        jsonObject.put("未整改", "0");
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                jsonObject.put("title", "已整改");
                jsonObject.put("value", "0");
            } else {
                jsonObject.put("title", "未整改");
                jsonObject.put("value", "0");
            }
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    @GetMapping("/data")
    public JSONArray d(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONArray jsonArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonObject1 = new JSONObject();
        JSONObject jsonObject2 = new JSONObject();
        jsonObject.put("hazardLevel", "一般隐患");//隐患级别
        jsonObject.put("nameOfHiddenTrouble", "P-1501泵甲醇密封罐的循环水换热回水视镜转子卡涩");//隐患名称
        jsonObject.put("personInCharge", "-");//责任人
        jsonObject.put("screenTime", "2022-04-15 20:11:38");//排查时间
        jsonObject.put("theRectificationDate", "2022-02-23 15:42:00");//整改日期

        jsonObject1.put("hazardLevel", "一般隐患");//隐患级别
        jsonObject1.put("nameOfHiddenTrouble", "1#乙烯装置急冷塔顶部出口采样器1100-S-11014柜内针阀未关闭，裂解气泄漏。");//隐患名称
        jsonObject1.put("personInCharge", "-");//责任人
        jsonObject1.put("screenTime", "2022-04-05 00:00:00");//排查时间
        jsonObject1.put("theRectificationDate", "2022-04-05 08:55:39");//整改日期

        jsonObject2.put("hazardLevel", "一般隐患");//隐患级别
        jsonObject2.put("nameOfHiddenTrouble", "后备液氧储罐静电释放柱一直报警");//隐患名称
        jsonObject2.put("personInCharge", "-");//责任人
        jsonObject2.put("screenTime", "2022-04-06 00:00:00");//排查时间
        jsonObject2.put("theRectificationDate", "2022-04-04 22:46:07");//整改日期

        jsonArray.add(jsonObject);
        jsonArray.add(jsonObject1);
        jsonArray.add(jsonObject2);
        return jsonArray;
    }

    private JSONArray bianli(JSONObject jsonObject){
        JSONArray jsonArray = new JSONArray();
//        JSONObject json = new JSONObject();
        Iterator iter = jsonObject.entrySet().iterator();
        while (iter.hasNext()) {
            JSONObject json = new JSONObject();
            Map.Entry entry = (Map.Entry) iter.next();
            json.put("title",entry.getKey().toString());
            json.put("value",entry.getValue().toString());
            jsonArray.add(json);
        }
        return jsonArray;
    }

}
